/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#include "EntityControl.h"

#include <QtGui/QLayout>
#include <QtGui/QMouseEvent>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QCheckBox>

namespace PQBuilder
{
	EntityAnimComboBox::EntityAnimComboBox(QWidget *parent,PQEngine::MeshComponent* component)
	{
		_component=component;
		if(_component==NULL){
			return;
		}
		std::vector<std::string> list=component->getAnimationNames();
		int size=list.size();
		for(int i=0;i<size;i++){
			this->insertItem(i,QString::fromStdString(list[i]));
		}

		connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(OnSelectChanged()));
	}

	void EntityAnimComboBox::OnSelectChanged()
	{
		if(_component!=NULL){
			_component->selectAnimation(this->currentIndex());
		}

	}

	EntityAnimComboBox::~EntityAnimComboBox()
	{
	}

	EntityControl::EntityControl(QWidget *parent,PQEngine::MeshComponent* component)
	{
		_component=component;
		if(component==0){
			return;
		}

		QGridLayout* grid=new QGridLayout(this);
		QLabel* labelAnimations=new QLabel(QObject::tr("Animations:"),this);
		EntityAnimComboBox* comboBox=new EntityAnimComboBox(this,component);

		QCheckBox* playAnimCheck=new QCheckBox(QObject::tr("Play Animation"));
		QCheckBox* hideMeshCheck=new QCheckBox(QObject::tr("Hide Mesh"));
		

		grid->addWidget(labelAnimations,0,0);
		grid->addWidget(comboBox,1,0);
		grid->addWidget(playAnimCheck,2,0);
		grid->addWidget(hideMeshCheck,3,0);
		
		
		this->setLayout(grid);
		this->setMaximumHeight(grid->rowCount()*28+12);

		//create mesh material
		
		connect(playAnimCheck, SIGNAL(stateChanged(int)), this, SLOT(playAnim(int)));
		connect(hideMeshCheck, SIGNAL(stateChanged(int)), this, SLOT(hideMesh(int)));
		
	}

	EntityControl::~EntityControl()
	{
	}

	void EntityControl::playAnim(int state)
	{
		/*
		Qt::Unchecked	0
		Qt::PartiallyChecked	1
		Qt::Checked	2
		*/
		if(_component){
			if(state==0){
				//_component->setAnimState(false);
			}else{
				//_component->setAnimState(true);
			}
		}
	}

	void EntityControl::hideMesh(int state)
	{
		
	}

}
